unit counterpartiescreateedit;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Buttons,
  StdCtrls, DbCtrls;

type

  { TfrmCounterPartiesCreateEdit }

  TfrmCounterPartiesCreateEdit = class(TForm)
    btnGroupSelect: TBitBtn;
    btnSave: TBitBtn;
    btnCencel: TBitBtn;
    DBEdtTitle: TDBEdit;
    DBMemInfo: TDBMemo;
    edtGroup: TEdit;
    lblTitle: TLabel;
    lblInfo: TLabel;
    lblGroup: TLabel;
    procedure btnCencelClick(Sender: TObject);
    procedure btnSaveClick(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
  private
    { private declarations }
  public
    { public declarations }
    CurrentGroupRecordNumber:Integer;
  end;

var
  frmCounterPartiesCreateEdit: TfrmCounterPartiesCreateEdit;

implementation

{$R *.lfm}

uses main,counterparties;

{ TfrmCounterPartiesCreateEdit }

procedure TfrmCounterPartiesCreateEdit.btnSaveClick(Sender: TObject);
begin
  FrmMain.DSCounterParties.DataSet.Edit;
  if (edtGroup.Text='') then begin
     CurrentGroupRecordNumber:=0;
  end;
  FrmMain.DSCounterParties.DataSet.FieldByName('parentid').AsInteger:=CurrentGroupRecordNumber;
  FrmMain.DSCounterParties.DataSet.FieldByName('group').AsBoolean:=False;
  FrmMain.DSCounterParties.DataSet.Post;
  FrmMain.DSCounterParties.DataSet.Refresh;
  Close;
end;

procedure TfrmCounterPartiesCreateEdit.btnCencelClick(Sender: TObject);
begin
  Close;
end;

procedure TfrmCounterPartiesCreateEdit.FormCloseQuery(Sender: TObject;
  var CanClose: boolean);
begin
  FrmMain.DSCounterParties.DataSet.Cancel;
end;

end.

